import re
import random

result = []
with open("code,title.txt", encoding="utf-8") as f:
    line = f.readlines()
    year = 2020
    while line:
        for e in line:
            tmp = e.split(",")
            name = tmp[1]
            if tmp[1].__contains__("（") and tmp[1].__contains__("）") and bool(re.search('[a-z]', tmp[1])):
                name = tmp[1][tmp[1].find("（") + 1: tmp[1].find("）")]

            if name.__contains__("\n"):
                name = name.replace("\n", "")

            if year <= 1903:
                year = 2020

            country = ["true", "false"]

            documentType = ["APP", "GRA"]
            arr = [tmp[0], name, str(country[random.randint(0, 1)]), str(documentType[random.randint(0, 1)])]
            year -= 1
            result.append(arr)
            if len(result) <= 3213:
                file_name = 'write.txt'
                with open(file_name, 'a') as file_obj:
                    file_obj.write(arr[0] + "," + arr[1] + "," + str(arr[2]) + "," + str(arr[3]))
                    file_obj.write("\n")
